import { createApp } from "vue";
import ElementPlus from "element-plus";
import "element-plus/theme-chalk/index.css";
import "element-plus/theme-chalk/dark/css-vars.css";
import pinia from "$store";
import { createRouter, createWebHistory } from "vue-router";
import "./asserts/custom.css";

export default (pageComponent, { routes, libs } = {}) => {
  const app = createApp(pageComponent);
  app.use(ElementPlus);
  app.use(pinia);

  if (libs && libs.length > 0) {
    libs.forEach((lib) => {
      app.use(lib);
    });
  }
  if (routes && routes.length > 0) {
    const router = createRouter({
      history: createWebHistory(),
      routes: [...routes],
    });
    app.use(router);
    router.isReady().then(() => {
      app.mount("#root");
    });
  } else {
    app.mount("#root");
  }
};
